#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void bubbleSort(int list[], int listLenght)  {
    while (listLenght--)  {
            bool swapped = false;

            for(int i = 0; i < listLenght; i++) {
                    if(list[i] > list[i + 1]){
                            swap(list[i], list[i + 1]);
                            swapped = true;
                    }
            }

            if(swapped == false) break;

    }
}


void read_from_file(const char *filename, int a[], int lenght) {
    ifstream file(filename);

    for(int i=0; i < lenght; i++)
        file >> a[i];
}
int main()
{


// B main
    #define LEN 5000
    int a[LEN];

    read_from_file("m1_sorted.txt",a,LEN);
    unsigned int t_start = clock();
    bubbleSort(a,LEN);
    unsigned int t_finish = clock();
    unsigned int t_work = t_finish - t_start;
    cout<<"m1_sorted " << t_work << " milliseconds \n";

    read_from_file("m2_reverse.txt",a,LEN);
    unsigned int t1_start = clock();
    bubbleSort(a,LEN);
    unsigned int t1_finish = clock();
    unsigned int t1_work = t1_finish - t1_start;
    cout<<"m2_reverse " << t1_work << " milliseconds \n";

    read_from_file("m3_shuffle.txt",a,LEN);
    unsigned int t2_start = clock();
    bubbleSort(a,LEN);
    unsigned int t2_finish = clock();
    unsigned int t2_work = t2_finish - t2_start;
    cout<<"m3_shuffle " << t2_work << " milliseconds \n";

    return 0;

}
